package com.lzx.indicatordemo.demo;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;

import com.framework.view.indicator.GodIndicator;
import com.framework.view.indicator.GodIndicatorAdapter;
import com.framework.view.indicator.configs.TextTitleConfig;
import com.framework.view.indicator.indicators.configs.WrapIndicatorConfig;
import com.framework.view.indicator.model.IndicatorShapeType;
import com.lzx.indicatordemo.Constants;
import com.lzx.indicatordemo.ExamplePager2Adapter;
import com.lzx.indicatordemo.R;

import java.util.Arrays;
import java.util.List;

import static com.lzx.indicatordemo.Constants.CHANNELS;
import static com.lzx.indicatordemo.Constants.normalTxtColors;

/**
 * description
 *
 * @author liangzx
 * @version 1.0
 * @time 2019-12-23 10:53
 **/
public class Viewpager2DemoActivity extends AppCompatActivity {

    private List<String> mDataList = Arrays.asList(CHANNELS);
    private ViewPager2 mViewPager;
    private ExamplePager2Adapter mExamplePagerAdapter = new ExamplePager2Adapter(mDataList);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewpager2_demo_activity);

        mViewPager = findViewById(R.id.vp);
        mViewPager.setAdapter(mExamplePagerAdapter);
        init1();
        init2();
        init3();
        init4();
        init5();
        init6();
    }

    private void init1() {
        final GodIndicator godIndicator = findViewById(R.id.g1);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<WrapIndicatorConfig>() {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.BLACK)
                        .setSelectedColor(Color.BLUE)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected WrapIndicatorConfig bindIndicatorConfig() {
                return WrapIndicatorConfig.factory()
                        .setColor(Color.parseColor("#96FFFFFF"))
                        .setPendingLeft(20)
                        .setPendingTop(10)
                        .setPendingRight(20)
                        .setPendingBottom(10);
            }
        });

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                godIndicator.getAdapter().bindViewPager(mViewPager);
            }
        }, 3000);
    }

    private void init2() {
        GodIndicator godIndicator = findViewById(R.id.g2);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<WrapIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.BLACK)
                        .setSelectedColor(Color.WHITE)
                        .setUseColorClip(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return 3;
            }

            @Override
            protected WrapIndicatorConfig bindIndicatorConfig() {
                return WrapIndicatorConfig.factory()
                        .setColor(Constants.randomWrapIndicatorColor())
                        .setPendingLeft(10)
                        .setPendingTop(10)
                        .setPendingRight(10)
                        .setPendingBottom(10);
            }

        });
    }

    private void init3() {
        GodIndicator godIndicator = findViewById(R.id.g3);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<WrapIndicatorConfig>(mViewPager, Arrays.asList(CHANNELS)) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.WHITE)
                        .setSelectedColors(Constants.selectedTxtColors)
                        .setUseColorClip(true)
                        .setSizeFollowSlideChange(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            protected WrapIndicatorConfig bindIndicatorConfig() {
                return WrapIndicatorConfig.factory()
                        .setColor(Constants.randomWrapIndicatorColor())
                        .setPendingLeft(10)
                        .setPendingTop(10)
                        .setPendingRight(10)
                        .setPendingBottom(10);
            }

        });
    }

    private void init4() {
        GodIndicator godIndicator = findViewById(R.id.g4);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<WrapIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.WHITE)
                        .setSelectedColors(Constants.selectedTxtColors)
                        .setColorGradientFollowSlide(true)
                        .setSizeFollowSlideChange(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected WrapIndicatorConfig bindIndicatorConfig() {
                return WrapIndicatorConfig.factory()
                        .setShapeType(IndicatorShapeType.RECT)
                        .setColor(Constants.randomWrapIndicatorColor())
                        .setPendingLeft(10)
                        .setPendingTop(10)
                        .setPendingRight(10)
                        .setPendingBottom(10);
            }

        });
    }

    private void init5() {
        GodIndicator godIndicator = findViewById(R.id.g5);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<WrapIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColors(normalTxtColors)
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setUseColorClip(true)
                        .setSizeFollowSlideChange(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected WrapIndicatorConfig bindIndicatorConfig() {
                return WrapIndicatorConfig.factory()
                        .setColors(Constants.wrapColors)
                        .setColorFollowSlideChange(true)
                        .setPendingLeft(10)
                        .setPendingTop(10)
                        .setPendingRight(10)
                        .setPendingBottom(10);
            }

        });
    }

    private void init6() {
        GodIndicator godIndicator = findViewById(R.id.g6);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<WrapIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColors(normalTxtColors)
                        .setSelectedColor(Constants.randomIndicatorColor())
                        .setUseColorClip(true)
                        .setSizeFollowSlideChange(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected WrapIndicatorConfig bindIndicatorConfig() {
                return WrapIndicatorConfig.factory()
                        .setStroke(true, 10)
                        .setColor(Constants.color("#96F0F0F0"))
                        .setColorFollowSlideChange(true)
                        .setPendingLeft(10)
                        .setPendingTop(10)
                        .setPendingRight(10)
                        .setPendingBottom(10);
            }

        });
    }

}
